<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@page import="java.io.*" %>
     <%@page import="mavenWebProject.userMapper" %>
     <%@page import="mavenWebProject.user" %>
     <%@page import="mavenWebProject.productsMapper" %>
     <%@page import="mavenWebProject.products" %>
     <%@page import="mavenWebProject.order" %>
     <%@page import="mavenWebProject.car" %>
     <%@page import="java.util.*" %>
     <%@page import="javax.servlet.*" %>
     <%@page import="org.apache.ibatis.io.Resources" %>
     <%@page import="org.apache.ibatis.session.SqlSession"%>
     <%@page import="org.apache.ibatis.session.SqlSessionFactory" %>
     <%@page import="org.apache.ibatis.session.SqlSessionFactoryBuilder" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员</title>
</head>

<style>
    body{font-family: 楷体;font-size: 18px;}

    table[id="tableGuide"]{
        position: absolute;
        top:0%;
        left:0%;
        width:100%;
        height:200px;
        background-color: black;
        color:white;
    }

    table[id="tableOrderManage"]{display:block;position: absolute;top:60px;left:0px;background-color:rgb(241,245,251);width:100%;height:700px;border-top-left-radius: 10px;border-top-right-radius: 10px;}
    
    a:link{color:white;text-decoration:none;padding:10px;}
    a:hover{padding:8px;border-radius: 5px;background-color: aliceblue;color:black;}
    a:visited:hover{color:black;}
    a:visited{color:white;}
    a[id="manageProducts"]{color:white;}
    a[id="manageProducts"]:hover{color:black;}
    a[id="tableProductsManageSearchButton"]{margin-left:20px;padding:8px;background-color:white;border-radius:8px;}

    p{margin:0px;}
</style>

<body>
  	<%
    String username=String.valueOf(session.getAttribute("username"));
    %>
	<table id="tableGuide" border="0" cellspacing="10px">
        <tr></tr>
 		<tr><td width="30px"></td><td width="60px"><a href="managerScene.jsp">首页</a></td><td width="100px"><a href="managerManageProducts.jsp">商品管理</a></td><td width="100px"><a href="managerManageOrder.jsp">订单管理</a></td><td width="100px"><a href="managerShowSold.jsp">销量排行</a></td><td width="100px"><a href="managerManagePurchaser.jsp">用户情况</a></td><td width="100px"></td><td align="right" width="800px">欢迎您：<font style="font-size:24px;margin:10px;color:cyan;"><%=username%></font>&nbsp;&nbsp;<a style="color:red" onClick="exit()">注销</a></td></tr>
         <tr><td colspan="8" height="150px"></tr>
    </table>

    <table id="tableOrderManage" border="0">
    <form id="orderManage">
        <tr><td width="150px" valign="bottom" height="50px"><font style="color:blue;font-size:22px;font-weight:bolder;margin-top:20px;margin-left:10px;">|订单管理</font></td><td width="1400px">&nbsp;</td></tr>
        <tr><td height="60px">&nbsp;</td><td><input placeholder="输入买家用户名/商品名/订单状态筛选你要的订单" id="searchOrder" name="searchOrder" type="text" style="border:1px solid black;width:400px;height:30px;border-radius:5px;background-color:rgb(0,0,0,0);"><a style="margin-left:20px;border-radius:8px;color:white;margin-top:10px;background-color:blueviolet;padding-right:15px;padding-left:15px;padding:8px;" onClick="searchOrder()">查找</a>
        <a style="margin-left:20px;border-radius:8px;color:white;margin-top:10px;background-color:blueviolet;padding-right:15px;padding-left:15px;padding:8px;" href="managerManageOrder.jsp">重置</a>
        <br>
        </td></tr>
        <tr><td>&nbsp;</td><td>
            <table border="0">
                <tr align="center" height="60px" style="font-size:20px;font-weight:bold;"><td colspan="2">商品信息</td><td>订单时间</td><td width="100px">单价/数量</td><td width="150px">买家/收货人</td><td width="100px">实付金额</td><td width="100px">订单状态</td><td width="150px">操作</td></tr>
                <tr><td colspan='8'><hr></td></tr>
                <%
                String resource = "mybatis-config.xml";
                request.setCharacterEncoding("utf-8");
            	InputStream inputStream = Resources.getResourceAsStream(resource);
            	SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            	SqlSession sqlsession=sqlSessionFactory.openSession();
            	
            	userMapper userMapper=sqlsession.getMapper(userMapper.class);
            	productsMapper productsMapper=sqlsession.getMapper(productsMapper.class);
                List<order> orderManage=productsMapper.selectAllOrders();
                int id=0;String purchaser="";String img="";String name="";int price=0;int amount=0;String size="";String stage="";String opentime="";String closetime="";
                String searchOrder="";String[] orderStage={};
                
               	searchOrder=request.getParameter("searchOrder");
               	String tempStr=request.getParameter("orderSearch");
       			if(orderStage!=null){
           			for(int i=1;i<=orderStage.length;i++){String temp="str"+i;temp=orderStage[i-1];}
					if(searchOrder==null){}
					else if(searchOrder!=null){}
           		}else{
           			out.println("<tr><td colspan='8' style='font-size:25px;color:red;'>无符合条件的订单</td></tr>");
           		}
       			String a="";
                for(order x:orderManage){
                	id=x.getId();purchaser=x.getUsername().trim();img=x.getImg().trim();name=x.getName().trim();price=x.getPrice();amount=x.getAmount();stage=x.getStage().trim();size=x.getSize().trim();opentime=x.getOpentime().trim();closetime=x.getClosetime().trim();
                	opentime="订单开启时间:"+opentime;
                	if(closetime.contentEquals("-1")){closetime="订单等待处理";}else{closetime="订单关闭时间:"+closetime;}
					if(stage.contentEquals("待发货")){
						a="<a style='border-radius:8px;padding:8px;background-color:blueviolet;color:white;margin-right:20px;' href='OrderManageServlet?do=发货&id="+id+"'>发货</a><a style='border-radius:8px;padding:8px;background-color:blueviolet;color:white;' href='OrderManageServlet?do=退回&id="+id+"'>退回</a>";
					}else{
						a="";
					}
	               	if(tempStr!=null){
	               		if(name.contains(searchOrder) || stage.contains(searchOrder) || username.contains(searchOrder)){
							out.println("<tr align='center'><td width='150px'><img src='"+img+"' width='150px' height='150px'></td><td align='left'>"+name+"(<font style='font-size:25px'>"+size+"</font>码)"+"</td><td align='left' width='250px' style='font-size:18px;'>"+opentime+"<br><br>"+closetime+"</td><td width='150px'>￥"+price+"/"+amount+"件 </td><td>"+purchaser+"</td><td>￥"+price*amount+"</td><td>"+stage+"</td><td>"+a+"</td></tr><tr><td colspan='8'><hr></td></tr>");
	               		}
	               	}else{
						out.println("<tr align='center'><td width='150px'><img src='"+img+"' width='150px' height='150px'></td><td align='left'>"+name+"(<font style='font-size:25px'>"+size+"</font>码)"+"</td><td align='left' width='250px' style='font-size:18px;'>"+opentime+"<br><br>"+closetime+"</td><td width='150px'>￥"+price+"/"+amount+"件 </td><td>"+purchaser+"</td><td>￥"+price*amount+"</td><td>"+stage+"</td><td>"+a+"</td></tr><tr><td colspan='8'><hr></td></tr>");
					}
				}
                %>
            </table>    
        </td></tr>
    </form>
    </table>
    <script>
    	function searchOrder(){
    		document.getElementById("orderManage").method="post";document.getElementById("orderManage").action="managerManageOrder.jsp?orderSearch=1";document.getElementById("orderManage").submit();
    	}
    </script>
    


</body>
</html>